function setErrorClass() {
/*    $("input.error").attr("class","textError");
    $("select.error").attr("class","selectError");
    $("textarea.error").attr("class","textareaError");*/
}

function resetErrorClass() {
    resetFormHints();
    $("input").attr("class","text");
    $("select").attr("class","text");
    $("textarea").attr("class","text");

    $("input[type=submit]").attr("class","myButton");
    $("input[type=reset]").attr("class","myButton");
}

function customVal(validators, formNode){
	
}

function customValHead(validators, formNode){
	
}

function errorOnLabels(formNode, validators) {
	// Reset all the labels
	 resetFormHints(formNode);
    //setErrorClass();
	 //appele la function de validations propres au form
	 customVal(validators, formNode);
	 customValHead(validators, formNode);

	for(var i=0; i<validators.length; i++){
		var s = validators[i].name;
		var i1 = s.indexOf("[");
		if(i1 != -1) {
			var i2 = s.indexOf("]");
			id = s.substring(0, i1) + "_" + s.substring(i1+1,i2);
		} else {
			var i2 = s.indexOf("_");
			if(i2 != -1) {
				id = s;
			}else{
				id = s;
				switch(s) {
					case 'passwordPwd':
						id = 'inscription_password';
						break;
					case 'passwordPwdBis':
						id = 'inscription_passwordbis';
						break;
				}
			}
		}
		var lbl = getLinkedLabel(id);
		if(lbl){
			x= lbl.parent().find(".errorMsg");
			if(x.length==0){
				x = lbl.parent().parent().find(".errorMsg");
			}
			x.css("color", "#FF0000");
			x.html(validators[i].message+'<br />');
			
		}
	}
	if(validators.length>0){
		//scroll(0,0);
		if(document.getElementById("errorDisplayHaut"+formNode.id)) {
			var errorDisplay = document.getElementById("errorDisplayHaut"+formNode.id); 
		}else{
			var errorDisplay = document.getElementById("errorDisplayHaut");
		}
	    userMsg = '';
		for(var i=0; i<validators.length; i++){
			if(typeof(getLabel) == 'function') {
				var label = getLabel(validators[i].name);
				if(label==undefined){
					label = validators[i].name;
				}
			}else{
				var label = validators[i].name;
			}
			var userMsg = userMsg + '<li>'+ label + ' : ' +  validators[i].message+'</li>'; 
		}
		if(errorDisplay) {
				errorDisplay.style.display = "block";
				errorDisplay.scrollIntoView (true);
				errorDisplay.innerHTML = '<ul class="error">'+__('Some fields on the form have errors.')+userMsg + '</ul>' ;
		}
		if(document.getElementById("errorDisplayBas"+formNode.id)) {
			var errorDisplay = document.getElementById("errorDisplayBas"+formNode.id); 
		}else{
			var errorDisplay = document.getElementById("errorDisplayBas");
		}
		if(errorDisplay) {
			errorDisplay.style.display = "block";
			errorDisplay.innerHTML = '<ul class="error">'+__('Some fields on the form have errors.')+userMsg + '</ul>' ;
		}
	}
	if(tmt.validator.lastStep == undefined){
		tmt.validator.lastStep = true;
	}
	if (validators.length == 0 && tmt.validator.lastStep){
		if(formNode.id==''){
			var allInputs = $(":input");
		}else{
			var allInputs = $("#" + formNode.id + " :input");	
		}
	    
	    for ( keyVar in allInputs ) { 
	    	   if(allInputs[keyVar].disabled){
	    		   allInputs[keyVar].disabled = false;
	    	   }
	    }
	}	
}

function getLinkedLabel(fieldID) {
	//var x = $(".formHint").parent().find("label");
	
	var x = $(".errorMsg").parent().find("label");
	for(var i=0; i<x.length; i++) {
		if(x.eq(i).attr("for") == fieldID) {
			return x.eq(i);
		}
	}
}



/* fonction ajouter le parametre obligatoire d'un champs
 * 
 * @param	-> idElement 	-> id de l'element
 * 			-> typeChamp	-> type de champs ('','combo','checkbox')
 * 			-> message		-> message d'erreur
 * @return	-> none
 */
function setMandatory(idElement, typeChamp, message)
{
	if(document.getElementById(idElement))
	{
		var cla = document.getElementById(idElement).className;
		var msg = '';
		
		if(cla.indexOf('required') == '-1')
		{
			if(message)
			{
				if(message == '')
				{
					msg = 'Champ obligatoire';
				}
				else
				{
					msg = message;
				}
			}
			else if(document.getElementById(idElement).getAttribute('tmt:message') == undefined)
			{
				msg = 'Champ obligatoire';
			}
			
			if(typeChamp == 'combo' || typeChamp ==  'BO')
			{
				document.getElementById(idElement).setAttribute('tmt:invalidindex', '0');
			}
			else if (typeChamp == 'checkbox')
			{
				document.getElementById(idElement).setAttribute('tmt:minchecked', '1');
			}
			else
			{
				document.getElementById(idElement).setAttribute('tmt:required', 'true');
			}
			document.getElementById(idElement).setAttribute('class', cla+' required');
			document.getElementById(idElement).setAttribute('className', cla+' required');
			if(msg)
			{
				document.getElementById(idElement).setAttribute('tmt:message', msg);
			}
		}
	}
}


/* fonction enlever le parametre obligatoire d'un champs
 * 
 * @param -> idElement -> id de l'element
 * @return -> none
 */
function setNonMandatory(idElement)
{
	if(document.getElementById(idElement))
	{
		document.getElementById(idElement).removeAttribute('tmt:invalidindex');
		document.getElementById(idElement).removeAttribute('tmt:required');
		document.getElementById(idElement).removeAttribute('tmt:minchecked');

		var cla = document.getElementById(idElement).className;
		cla = cla.replace(" required","");
		document.getElementById(idElement).setAttribute('class', cla);
		document.getElementById(idElement).setAttribute('className', cla);		
	}
}


function resetFormHints() {
	var x = $(".errorMsg");
	for(var i=0; i<x.length; i++) {
		//x.css("color", "#181B2A");
		x.html("&nbsp;");
	}
	if(document.getElementById("errorDisplayHaut")) {
		document.getElementById("errorDisplayHaut").innerHTML = '';
	}
	if(document.getElementById("errorDisplayBas")) {
		document.getElementById("errorDisplayBas").innerHTML = '';
	}
}
function displayError(formNode, validators){
    setErrorClass();
	 //appele la function de validations propres au form
	customVal(validators);
	customValHead(validators);
	var errorHTML = "";
	for(var i=0; i < validators.length; i++){
		//errorHTML += "<li><em>" + validators[i].name + '</' + 'em>: ' + validators[i].message + "</li>";
		errorHTML += "<li>" + validators[i].message + '<' + '/li>';
	}
	if(validators.length != 0) {
		if(document.getElementById("errorDisplayHaut")) {
			document.getElementById("errorDisplayHaut").style.display = "block";
			document.getElementById("errorDisplayHaut").innerHTML = '<ul class="error">' + errorHTML + "</ul>";
		}
		if(document.getElementById("errorDisplayBas")) {
			document.getElementById("errorDisplayBas").style.display = "block";
			document.getElementById("errorDisplayBas").innerHTML = '<ul class="error">' + errorHTML + "</ul>";
		}
	}
}

function popupError(formNode, validators){
	var errorHTML = validators[0].message;
    alert(errorHTML);
}

function textCounter(field, cntfield, maxlimit) {
	if (field.value.length > maxlimit) // if too long...trim it!
		field.value = field.value.substring(0, maxlimit);
	else
		cntfield.value = maxlimit - field.value.length;
}

function fOnChangePieceJointe () {
	// affiche le nom du fichier image car on ne le voit pas bien dans le champ

	/*
	var x = this.value;
	alert(x);
	alert(this.name);
    var n = 'idRappel' + this.name;
    alert(n);
    */
	document.getElementById('idRappelPieceJointe').innerHTML = document.getElementById('idPieceJointe').value;
}

function verifdt(dateavalider){
	
	verdat=dateavalider;//document.getElementById("demandes3_nom_guichet").value;
	/*datej= new Date();
	anneej=datej.getFullYear()+"*";
	anneej=anneej.substring(2,0);

	if (verdat.length ==6) 
	verdat=verdat.substring(2,0)+"/"+verdat.substring(4,2)+"/"+anneej+verdat.substring(6,4);
	*/
	if (verdat.length ==10){
		//verdat=verdat.substring(2,0)+"/"+verdat.substring(4,2)+"/"+verdat.substring(8,4);
		
		if(!isValidDate(verdat))
		    //alert("la date n'est pas valide ou n'est pas au bon format.\n format : jjmmaa ou jjmmaaaa ou jj/mm/aaaa");
			return false;
		else
			//dateavalider.value = verdat;
			return true;
	}else {
		return false;
	}

	
}

function isValidDate(d) {
	var dateRegEx = /^((((0?[1-9]|[12]\d|3[01])[\.\-\/](0?[13578]|1[02])[\.\-\/]((1[6-9]|[2-9]\d)?\d{2}))|((0?[1-9]|[12]\d|30)[\.\-\/](0?[13456789]|1[012])[\.\-\/]((1[6-9]|[2-9]\d)?\d{2}))|((0?[1-9]|1\d|2[0-8])[\.\-\/]0?2[\.\-\/]((1[6-9]|[2-9]\d)?\d{2}))|(29[\.\-\/]0?2[\.\-\/]((1[6-9]|[2-9]\d)?(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00)|00)))|(((0[1-9]|[12]\d|3[01])(0[13578]|1[02])((1[6-9]|[2-9]\d)?\d{2}))|((0[1-9]|[12]\d|30)(0[13456789]|1[012])((1[6-9]|[2-9]\d)?\d{2}))|((0[1-9]|1\d|2[0-8])02((1[6-9]|[2-9]\d)?\d{2}))|(2902((1[6-9]|[2-9]\d)?(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00)|00))))$/;
	return d.match(dateRegEx);
} 

function isNumeric(n) {
	return !isNaN(parseFloat(n)) && isFinite(n);
}

/******************************************************************
# NOM : bonmail()
# BUT : Verifier le format d'une adresse e-mail
# E : L'adresse e-mail
# S : Booleen
# COM :
# *******************************************************************/

function bonmail(mailteste)

{
	var reg = new RegExp('^[a-z0-9._-]+@[a-z0-9._-]{2,}\.[a-z]{2,4}$', 'i');

	if(reg.test(mailteste))
	{
		return(true);
	}
	else
	{
		return(false);
	}
}

function verifierDNS(dns, type){
	 formatDns = true;
	 if(dns.substr(0,1).toUpperCase() !="K"){
		 formatDns = false;
	 }
	 switch (type){
		 case "pos":
			 if(dns.substr(3,2)!="20" && dns.substr(3,2)!="21"){
				 formatDns = false;
		 	 }
			 break;

		 case "imp":
			 if(dns.substr(3,2)!="22"){
				 formatDns = false;
		 	 }
			 break;
		 case "ser":
			 if(dns.substr(3,2)!="23"){
				 formatDns = false;
		 	 }
			 break;
	 }
	 if(dns.length!=8){
		 formatDns = false;
	 }
	 return(formatDns);
}
/******************************************************************
# NOM : Verifier_Numero_Telephone()
# BUT : Verifier le format d'un numero de telephone (01|02|03|04|05|06|08) + suite de chiffres
# E : Le numero de telephone
# S : Booleen
# COM :
# *******************************************************************/

function Verifier_Numero_Telephone(num_tel)
{
	// D�finition du motif a matcher
	var regex = new RegExp("^0[1-9][0-9]{8}$", "g");
	
	// Test sur le motif
	if(regex.test(num_tel))
	{
		return(true);
	}
	else
	{
		return(false);
	}
} 

/******************************************************************
# NOM : Verifier_CodePostal()
# BUT : Verifier le format d'un code postal
# E : Le code postal
# S : Booleen
# COM :
# *******************************************************************/

function Verifier_CodePostal(codepos)
{
	// D�finition du motif a matcher
	var regex = new RegExp("^[0-9]{5}$", "g");
	
	// Test sur le motif
	if(regex.test(codepos))
	{
		return(true);
	}
	else
	{
		return(false);
	}
}

/******************************************************************
# NOM : Verifier_alpha()
# BUT : Verifier le format texte sans chiffre
# E : Le texte
# S : Booleen
# COM :
# *******************************************************************/

function Verifier_alpha(texte)
{
	// D�finition du motif a matcher
	var regex = new RegExp("[a-zA-Z]", "g");
	
	// Test sur le motif
	if(regex.test(texte))
	{
		return(true);
	}
	else
	{
		return(false);
	}
}

/******************************************************************
# NOM : Verifier_num()
# BUT : Verifier le format chiffre sans texte
# E : Le texte
# S : Booleen
# COM :
# *******************************************************************/

function Verifier_num(texte)
{
	// D�finition du motif a matcher
	var regex = new RegExp("[0-9]", "g");
	
	// Test sur le motif
	if(regex.test(texte))
	{
		return(true);
	}
	else
	{
		return(false);
	}
}
/*Fonction pour valider les formulaires avec CHSCT*/

function validerCHSCT(validators){
	var date = document.getElementById("demandes3_date_c").value;
	var lieu = document.getElementById("demandes3_lieu_c").value;

	if(document.getElementById('demandes3_propos').options[document.getElementById('demandes3_propos').selectedIndex].text == 'Oui' && lieu == "")
	{
		x = validators.length;
		validators.push(tmt.validator.fieldValidatorFactory(document.getElementById("demandes3_lieu_c")));
		validators[x].message = "Veuillez saisir un lieu.";
	}

	if(document.getElementById('demandes3_propos').options[document.getElementById('demandes3_propos').selectedIndex].text == 'Oui' && date == "")
	{
		x = validators.length;
		validators.push(tmt.validator.fieldValidatorFactory(document.getElementById("demandes3_date_c")));
		validators[x].message = "Veuillez saisir la date.";
	}		
	/*
	** Gestion des dates p�rim�es
	*/
	// Calcul de la date actuelle, Format YYYYMMJJ
	var currentTime = new Date();
	var month = currentTime.getMonth() + 1;
	var day = currentTime.getDate();
	var year = currentTime.getFullYear();
	if(day < 10)
	{
		day = "0" + day;
	}
	if(month < 10)
	{
		month = "0" + month;
	}
	var datedujour = year + month + day;

	// Transformation de la date de d�but en format YYYYMMJJ
	var jourDebut = date.substring(0,2);
	var moisDebut = date.substring(3,5);
	var anneeDebut = date.substring(6,10);

	var maDateDebut = anneeDebut + moisDebut + jourDebut;
	
	if(date != "")
	{
		if(maDateDebut > datedujour)
		{
			//x = validators.length;
			//validators.push(tmt.validator.fieldValidatorFactory(document.getElementById("demandes3_date_c")));
			//validators[x].message="Date sup&eacute;rieure &agrave; la date du jour.";
		}
	}
}

function validateDatesBadges(validators){
	var temp_du = document.getElementById('demandes3_temp_du').value;
	var temp_au = document.getElementById('demandes3_temp_au').value;

	// Si la dur�e est provisoire et la date de d�but est vide
	if(temp_au == "" && document.getElementById('demandes3_statut').value == 'pro')
	{
		x = validators.length;
		validators.push(tmt.validator.fieldValidatorFactory(document.getElementById("demandes3_temp_au")));
		validators[x].message="Champ obligatoire";
	}

	// Si la dur�e est provisoire et la date de fin est vide
	if(temp_du == "" && document.getElementById('demandes3_statut').value == 'pro')
	{
		x = validators.length;
		validators.push(tmt.validator.fieldValidatorFactory(document.getElementById("demandes3_temp_du")));
		validators[x].message="Champ obligatoire";
	}

	// Si le parking est � oui et le type de v�hicule est vide
	if(document.getElementById('demandes3_type').value == "" && document.getElementById('demandes3_parking').options[document.getElementById('demandes3_parking').selectedIndex].text == 'Oui')
	{
		x = validators.length;
		validators.push(tmt.validator.fieldValidatorFactory(document.getElementById("demandes3_type")));
		validators[x].message="Champ obligatoire";
	}		

	if(document.getElementById('demandes3_statut').value == 'pro'){
		/*
		** Gestion des dates p�rim�es
		*/
		// Date du jour
		var currentTime = new Date();
		var dateDuJour = new Date(currentTime.getFullYear(),currentTime.getMonth(),currentTime.getDate(),0 ,0,0,0);
		
		var dateDebut = getFieldDate(document.getElementById('demandes3_temp_du').value);
		var datefin = getFieldDate(document.getElementById('demandes3_temp_au').value);
		
		if(temp_du != "")
		{
			if(dateDebut < dateDuJour)
			{
				x = validators.length;
				validators.push(tmt.validator.fieldValidatorFactory(document.getElementById("demandes3_temp_du")));
				validators[x].message="Date inf&eacute;rieure &agrave; la date du jour.";
			}
		}
	
		if(temp_au != "")
		{
			if(datefin < dateDuJour)
			{
				x = validators.length;
				validators.push(tmt.validator.fieldValidatorFactory(document.getElementById("demandes3_temp_au")));
				validators[x].message="Date inf&eacute;rieure &agrave; la date du jour.";
			}
		}
	
		/*
		** Verification des dates minimums
		** La date de debut doit �tre au moins trois jours apres la date du jour
		*/
	
		//Set 1 day in milliseconds
		var one_day=1000*60*60*24;
	
		// On compare si la date de fin est pr�c�dente � la date actuelle
		if(dateDebut >= dateDuJour)
		{
			var debut = dateDebut.getTime();
			//var fin = dateFin.getTime();
			
			//Calculate difference btw the two dates, and convert to days
			var nb = Math.ceil((debut-dateDuJour)/(one_day));
			
			// On regarde s'il y a un �cart de 3 jours entre la date de fin et la date du jour.
			if(nb <= 3)
			{
				x = validators.length;
				validators.push(tmt.validator.fieldValidatorFactory(document.getElementById("demandes3_temp_du")));
				validators[x].message="La date doit &ecirc;tre sup&eacute;rieure de 3 jours par rapport &agrave; la date du jour";
			}
		}
	}
}

// Fonction pour calculer le temps en jours
// Return d nombre de jours
function temps(date)
{
	var d = new Date(date[2], date[1] - 1, date[0]);
	return d.getTime();
}
/*
 * 
 * FONCTION TRIM, LTRIM, RTRIM
 * SUPPRIME TOUT LES ESPACES EN DEBUT ET EN FIN DE CHAINE
 * 
 */
function trim(str, chars)
{
	return ltrim(rtrim(str, chars), chars);
}
 
function ltrim(str, chars)
{
	chars = chars || "\\s";
	return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
}
 
function rtrim(str, chars) 
{
	chars = chars || "\\s";
	return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
}


$(document).ready(function() {
 // hides the slickbox as soon as the DOM is ready
 // (a little sooner than page load)
  $('#slickbox').hide();
 // shows the slickbox on clicking the noted link  
  $('a#slick-show').click(function() {
    $('#slickbox').show('slow');
    return false;
  });
 // hides the slickbox on clicking the noted link  
  $('a#slick-hide').click(function() {
    $('#slickbox').hide('fast');
    return false;
  });
 
 // toggles the slickbox on clicking the noted link  
  $('a#slick-toggle').click(function() {
    $('#slickbox').toggle(400);
    return false;
  });
  
  // toggles the slickbox on clicking the noted link  
  $('a#slick-toggle1').click(function() {
    $('#slickbox1').toggle(400);
    return false;
  });
});


/*
 * Tooltip script 
 */
this.tooltip = function()
{	
	/* CONFIG */		
	xOffset = 10;
	yOffset = 20;		
	// these 2 variable determine popup's distance from the cursor
	// you might want to adjust to get the right result		
	/* END CONFIG */
	$("input.tooltip").hover(function(e){											  
		this.t = this.title;
		this.title = "";									  
		$("body").append("<p id='tooltip'>"+ this.t +"</p>");
		$("#tooltip")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px")
			.fadeIn("fast");		
    },
	function(){
		this.title = this.t;		
		$("#tooltip").remove();
    });	
	$("input.tooltip").mousemove(function(e){
		$("#tooltip")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px");
	});
	
	$("a.tooltip").hover(function(e){											  
		this.t = this.title;
		this.title = "";									  
		$("body").append("<p id='tooltip'>"+ this.t +"</p>");
		$("#tooltip")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px")
			.fadeIn("fast");		
    },
	function(){
		this.title = this.t;		
		$("#tooltip").remove();
    });	
	$("a.tooltip").mousemove(function(e){
		$("#tooltip")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px");
	});
	
	$("span.tooltip").hover(function(e){											  
		this.t = this.title;
		this.title = "";									  
		$("body").append("<p id='tooltip'>"+ this.t +"</p>");
		$("#tooltip")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px")
			.fadeIn("fast");		
    },
	function(){
		this.title = this.t;		
		$("#tooltip").remove();
    });	
	$("span.tooltip").mousemove(function(e){
		$("#tooltip")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px");
	});
	
	$("div.tooltip").hover(function(e){											  
		this.t = this.title;
		this.title = "";									  
		$("body").append("<p id='tooltip'>"+ this.t +"</p>");
		$("#tooltip")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px")
			.fadeIn("fast");		
    },
	function(){
		this.title = this.t;		
		$("#tooltip").remove();
    });	
	$("div.tooltip").mousemove(function(e){
		$("#tooltip")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px");
	});
};

// starting the script on page load
$(document).ready(function(){
	tooltip();
});

function printDiv() 
{ 
	var divToPrint=document.getElementById('DivIdToPrint'); 
	var newWin=window.open('','','width=auto,height=auto');
	newWin.document.open();
	newWin.document.write('<html><head><link href="/css/default/design.css" media="all" type="text/css" rel="stylesheet"><link href="/css/printdesign.css" media="all" type="text/css" rel="stylesheet"></head><body ><div id="container"><div id="col3">'+divToPrint.innerHTML+'</div><div></body></html>');
	//onload="window.print()"
	newWin.focus();
	newWin.print();
	newWin.document.close(); 
	setTimeout(function(){newWin.close();},10); 
}

function refreshSelect(selectId, values, keys, defaultValue) {
	var select = document.getElementById(selectId);
	select.options.length=0;
	j = 0;
	/*First foreach, to be sure empty value is the first option. 
	 * It's not the case in every browser
	 * At the same time, I build an array to sort the elemts by the text
	 * */
	var sortable = [];
	for (var i in values) {
		if(i==''){
			select.options.length ++;
			if(keys){
				select.options[j].value = keys[i];
			}else{
				select.options[j].value = i;
			}
			select.options[j].text = values[i];
			j ++;
		}else{
			sortable.push([i, values[i]]);
		}
	}	
	if(keys){
		for (var i in values) {
			if(i!=''){
				select.options.length ++;
				if(keys){
					select.options[j].value = keys[i];
				}else{
					select.options[j].value = i;
				}
				select.options[j].text = values[i];
				j ++;
			}
		}
	}else{
		/*Sort the elems of the values*/
		sortable.sort(function(a, b) { return (a[1].toUpperCase()<b[1].toUpperCase()?"-1":"1")});
		
		for (var i=0; i<sortable.length; i++) {
			select.options.length ++;
			select.options[j].value = sortable[i][0];
			select.options[j].text = sortable[i][1];
			j ++;
		}
		/*for (var i in values) {
			if(i!=''){
				select.options.length ++;
				if(keys){
					select.options[j].value = keys[i];
				}else{
					select.options[j].value = i;
				}
				select.options[j].text = values[i];
				j ++;
			}
		}
		*/
	}
	
	select.value = defaultValue;
}

/* function that takes blanks as 0 
 * 
 * */
function binoParseFloat(string, nbr_digits)
{
	if(string=='')
	{
		string = 0;
	}
	return parseFloat(string);
		
}

function round (value, precision, mode) {
	  // http://kevin.vanzonneveld.net
	  // +   original by: Philip Peterson
	  // +    revised by: Onno Marsman
	  // +      input by: Greenseed
	  // +    revised by: T.Wild
	  // +      input by: meo
	  // +      input by: William
	  // +   bugfixed by: Brett Zamir (http://brett-zamir.me)
	  // +      input by: Josep Sanz (http://www.ws3.es/)
	  // +    revised by: Rafa Kukawski (http://blog.kukawski.pl/)
	  // %        note 1: Great work. Ideas for improvement:
	  // %        note 1:  - code more compliant with developer guidelines
	  // %        note 1:  - for implementing PHP constant arguments look at
	  // %        note 1:  the pathinfo() function, it offers the greatest
	  // %        note 1:  flexibility & compatibility possible
	  // *     example 1: round(1241757, -3);
	  // *     returns 1: 1242000
	  // *     example 2: round(3.6);
	  // *     returns 2: 4
	  // *     example 3: round(2.835, 2);
	  // *     returns 3: 2.84
	  // *     example 4: round(1.1749999999999, 2);
	  // *     returns 4: 1.17
	  // *     example 5: round(58551.799999999996, 2);
	  // *     returns 5: 58551.8
	  var m, f, isHalf, sgn; // helper variables
	  precision |= 0; // making sure precision is integer
	  m = Math.pow(10, precision);
	  value *= m;
	  sgn = (value > 0) | -(value < 0); // sign of the number
	  isHalf = value % 1 === 0.5 * sgn;
	  f = Math.floor(value);

	  if (isHalf) {
	    switch (mode) {
	    case 'PHP_ROUND_HALF_DOWN':
	      value = f + (sgn < 0); // rounds .5 toward zero
	      break;
	    case 'PHP_ROUND_HALF_EVEN':
	      value = f + (f % 2 * sgn); // rouds .5 towards the next even integer
	      break;
	    case 'PHP_ROUND_HALF_ODD':
	      value = f + !(f % 2); // rounds .5 towards the next odd integer
	      break;
	    default:
	      value = f + (sgn > 0); // rounds .5 away from zero
	    }
	  }

	  return (isHalf ? value : Math.round(value)) / m;
	}


$(function()
{
	$(".helper").hide();
	
	$("#col2").click(function()
	{
		$(".helper").slideToggle();
	}); 
});

function setJqueryDatePicker(field_id, culture, timestamp, changeMonth, changeYear, showButtonPannel, numberOfMonths, button_img){
	params = new Object;
	culture = culture.substr(0, 2);
	if(culture!='en'){
		
		var params = $.datepicker.regional[culture];
	}
    field_id = "#" + field_id;
	
	params.changeMonth = changeMonth;
	params.changeYear = changeYear;
	params.numberOfMonths = numberOfMonths;
	params.showButtonPanel = showButtonPannel;
	params.buttonImage = button_img;
	params.buttonImageOnly = true;
	params.showOn = "button";
	if(timestamp){
	    params.timeFormat = 'hh:mm:ss';
	    $(field_id).datetimepicker(params);
	}else{
	   	$(field_id).datepicker(params);
	}
}

function showHideSubList(id)
{
	if(document.getElementById(id).style.display == 'none')
	{
		document.getElementById(id).style.display = 'block';
		document.getElementById(id+'toggleButton').setAttribute('src','/images/icons/16/toggle_button_up.png');
	}
	else
	{
		document.getElementById(id).style.display = 'none';
		document.getElementById(id+'toggleButton').setAttribute('src','/images/icons/16/toggle_button_down.png');
	}
}
